#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400005;
long long a[MAXN], sa[MAXN]; bool tg[MAXN];
namespace sgt {
	int cnt[MAXN << 2]; unsigned long long su[MAXN << 2], su2l[MAXN << 2], su2r[MAXN << 2];
	void pushup(int rt) {
		cnt[rt] = cnt[rt << 1] + cnt[rt << 1 | 1];
		su[rt] = su[rt << 1] + su[rt << 1 | 1];
		su2l[rt] = su2l[rt << 1] + su2l[rt << 1 | 1] + su[rt << 1] * cnt[rt << 1 | 1];
		su2r[rt] = su2r[rt << 1] + su2r[rt << 1 | 1] + su[rt << 1 | 1] * cnt[rt << 1];
	}
	void add(int rt, int l, int r, int x) {
		if (l == r) return cnt[rt] = 1, su[rt] = su2l[rt] = su2r[rt] = sa[x], void();
		int mid = (l + r) >> 1;
		x <= mid ? add(rt << 1, l, mid, x) : add(rt << 1 | 1, mid + 1, r, x); pushup(rt);
	}
	void del(int rt, int l, int r, int x) {
		if (l == r) return cnt[rt] = 0, su[rt] = su2l[rt] = su2r[rt] = 0, void();
		int mid = (l + r) >> 1;
		x <= mid ? del(rt << 1, l, mid, x) : del(rt << 1 | 1, mid + 1, r, x); pushup(rt);
	}
	bool queryl(int rt, int l, int r, int &w, unsigned long long &s) {
		if (cnt[rt] < w) return w -= cnt[rt], s += su[rt], 0; if (l == r) return s += su[rt], 1;
		int mid = (l + r) >> 1; if (queryl(rt << 1, l, mid, w, s)) return 1; else return queryl(rt << 1 | 1, mid + 1, r, w, s);
	}
	bool queryr(int rt, int l, int r, int &w, unsigned long long &s) {
		if (cnt[rt] < w) return w -= cnt[rt], s += su[rt], 0; if (l == r) return s += su[rt], 1;
		int mid = (l + r) >> 1; if (queryr(rt << 1 | 1, mid + 1, r, w, s)) return 1; else return queryr(rt << 1, l, mid, w, s);
	}
	bool queryls(int rt, int l, int r, int &w, unsigned long long &s2) {
		if (cnt[rt] < w) return w -= cnt[rt], s2 += su2l[rt] + w * su[rt], 0; if (l == r) return s2 += su2l[rt], 1;
		int mid = (l + r) >> 1; if (queryls(rt << 1, l, mid, w, s2)) return 1; else return queryls(rt << 1 | 1, mid + 1, r, w, s2);
	}
	bool queryrs(int rt, int l, int r, int &w, unsigned long long &s2) {
		if (cnt[rt] < w) return w -= cnt[rt], s2 += su2l[rt] + w * su[rt], 0; if (l == r) return s2 += su2l[rt], 1;
		int mid = (l + r) >> 1; if (queryrs(rt << 1 | 1, mid + 1, r, w, s2)) return 1; else return queryrs(rt << 1, l, mid, w, s2);
	}
}
char buf[1 << 24], *S, *E;
char gc() {return (S == E && (E = (S = buf) + fread(buf, 1, 1 << 24, stdin)) == buf) ? 0 : *(S++);}
long long read() {
	char ch; while ((ch = gc()) <= ' '); long long x = ch - '0';
	while ((ch = gc()) > ' ') x = 10 * x + ch - '0'; return x;
}
int main() {
	freopen("kte.in", "r", stdin);
	freopen("kte.out", "w", stdout);
	double st = clock();
	int q = read(); for (int i = 1; i <= q; i++) sa[i] = a[i] = read();
	sort(sa + 1, sa + 1 + q); int n = unique(sa + 1, sa + 1 + q) - sa - 1;
	for (int i = 1, c = 0; i <= q; i++) {
		a[i] = lower_bound(sa + 1, sa + 1 + n, a[i]) - sa;
		if (tg[a[i]]) tg[a[i]] = 0, sgt::del(1, 1, n, a[i]), c--;
		else tg[a[i]] = 1, sgt::add(1, 1, n, a[i]), c++;
		int l = 0, r = (c + 1) / 2; while (l + 1 < r) {
			int mid = (l + r) >> 1, tmp; unsigned long long s1 = 0, s2 = 0;
			tmp = mid; sgt::queryr(1, 1, n, tmp, s2);
			tmp = mid + 1; sgt::queryl(1, 1, n, tmp, s1);
			if (s2 >= s1) r = mid; else l = mid;
		}
		if (r == (c + 1) / 2) printf("%llu\n", sgt::su2r[1] - sgt::su2l[1]);
		else {
			unsigned long long s1 = 0, s2 = 0, s3 = 0, s4 = 0; int tmp;
			tmp = r - 1; if (tmp) sgt::queryls(1, 1, n, tmp, s1);
			tmp = r - 1; if (tmp) sgt::queryrs(1, 1, n, tmp, s2);
			tmp = r; sgt::queryl(1, 1, n, tmp, s3);
			tmp = c - r; sgt::queryr(1, 1, n, tmp, s4);
			printf("%llu\n", 2 * (s2 - s1) + s4 - s3);
		}
	}
	double ed = clock();
	fprintf(stderr, "%lf\n", (ed - st) / CLOCKS_PER_SEC);
}
/*
cd "d:\Codes\2024.12.4\kte\" && g++ kte.cpp -o kte -std=c++14 -O2 -Wall -Wl,--stack=2048000000 && "d:\Codes\2024.12.4\kte\"kte < kte1.in > kte1.out
cd "d:\Codes\2024.12.4\kte\" && g++ kte.cpp -o kte -std=c++14 -O2 -Wall -Wl,--stack=2048000000 && "d:\Codes\2024.12.4\kte\"kte < kte2.in > kte2.out
cd "d:\Codes\2024.12.4\kte\" && g++ kte.cpp -o kte -std=c++14 -O2 -Wall -Wl,--stack=2048000000 && "d:\Codes\2024.12.4\kte\"kte < kte3.in > kte3.out
fc kte1.out kte1.ans /W
fc kte2.out kte2.ans /W
fc kte3.out kte3.ans /W
*/